<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
class Cookies{

    /**
     * 设置cookies
     * @param <type> $name
     * @param <type> $value
     * @param <type> $expire
     */
    public static function set($name, $value, $expire=3153600){
        $life   = 3600 * 24 * 365 * 10;
        setcookie($name, $value, $life + time(), '/', '.u22.cc');
        setcookie($name, $value, $life + time(), '/', 'www.u22.cc');
        setcookie($name, $value, $life + time(), '/', '.u22.cc');
    }

    /**
     * 获取cookies
     * @param <type> $name
     * @return <type>
     */
    public static function get($name) {
        if(key_exists($name, $_COOKIE)){
            $return = $_COOKIE["$name"];
        }else{
            $return = null;
        }
        return rawurldecode($return);
    }

    /**
     * 移除cookies
     * @param <type> $name
     * @param <type> $expire
     */
    public static function remove($name, $expire=3153600){
        $life   = 3600 * 24 * 365 * 10;
        setcookie($name, $value, time() - $life, '/', '.u22.cc');
        setcookie($name, $value, time() - $life, '/', 'www.u22.cc');
        setcookie($name, $value, time() - $life, '/', '.u22.cc');
    }

    /**
     * 设置本站cookies
     * @param <type> $value
     */
    public static function setMine($value) {
        $history    = Cookies::get('u22_url');
        if(!empty($history)){
            $history    = passport_decrypt($history);
            $history    = explode(',', $history);
            array_push($history, $value);
            
            $value    = implode(',', $history);
        }
        $value    = passport_encrypt($value);
        self::set('u22_url', $value);
    }

    /**
     * 获取本站cookies
     * @param <type> $name
     * @return <type>
     */
    public static function getMine($name) {
        return passport_decrypt(self::get($name));
    }
}
?>
